package com.yq.testmodule.recycleview

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.fmt.mvi.learn.gobal.log
import com.yq.testmodule.R

open class CommonAdapter(var datas: ArrayList<String>) : RecyclerView.Adapter<ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        "onCreateViewHolder ".log()
        val inflate = LayoutInflater.from(parent.context).inflate(R.layout.item_simple, parent,false)
//        //设置inflate 高度为 父容器高度的80%
//        val layoutParams = ViewGroup.LayoutParams(
//            ViewGroup.LayoutParams.MATCH_PARENT,
//            (parent.measuredHeight * ITEM_HEIGHT_PRE).toInt()
//        )
//        inflate.layoutParams = layoutParams
        return MyViewHolder(inflate)
    }

    class MyViewHolder(itemView: View) : ViewHolder(itemView) {


    }

    override fun getItemCount(): Int {
        return datas.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        "onBindViewHolde $position".log()
        val tv = holder.itemView.findViewById<TextView>(R.id.tvItem)
        tv.text = datas[position]


//        //随机设置tv高度,最大不超过屏幕高度
//        val layoutParams = tv.layoutParams
//        layoutParams.height = (Math.random() * 1000).toInt()
    }

}